<template>
  <div class="all">
    <el-row :gutter="8">
      <el-col :span="1.2">
        <div class="grid-content bg-purple">
          <span>商品名称</span>
        </div>
      </el-col>
      <el-col :span="3">
        <div class="grid-content bg-purple">
          <el-select v-model="value" placeholder="全部" class="mingcheng">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled"
            />
          </el-select>
        </div>
      </el-col>
      <el-col :span="1.2">
        <div class="grid-content bg-purple">
          <span>商品编号</span>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="grid-content bg-purple">
          <el-select v-model="value" placeholder="全部" class="bianhao">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled"
            />
          </el-select>
        </div>
      </el-col>
      <el-col :span="2" :offset="1">
        <div class="grid-content bg-purple">
          <el-button class="add" @click="toDoodsAdd">+新增商品</el-button>
        </div>
      </el-col>
      <el-col :span="2">
        <div class="grid-content bg-purple">
          <el-button class="remove">批量删除</el-button>
        </div>
      </el-col>
      <el-col :span="2" :offset="3">
        <div class="grid-content bg-purple">
          <el-button class="reset">重置</el-button>
        </div>
      </el-col>
      <el-col :span="2">
        <div class="grid-content bg-purple">
          <el-button class="sure">确定</el-button>
        </div>
      </el-col>
    </el-row>
  </div>

  <!-- 表单 -->
  <div class="form">
    <el-table
      ref="multipleTableRef"
      :data="tableData"
      style="width: 100%"
      :stripe="true"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="40" />
      <el-table-column label="订单编号" width="200">
        <template #default="scope">{{ scope.row.date }}</template>
      </el-table-column>
      <el-table-column property="name" label="名称" width="142" />
      <el-table-column property="freight" label="运费" width="123" />
      <el-table-column property="price" label="销售价格" width="150" />
      <el-table-column property="supplier" label="供应商" width="356" />
      <el-table-column property="activity" label="活动类型" width="238" />
      <el-table-column fixed="right" label="操作" width="200">
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">
            修改
          </el-button>
          <el-button
            size="small"
            @click="handleDelete(scope.$index, scope.row)"
          >
            删除
          </el-button>
          <el-button
            size="small"
            @click="handleDelete(scope.$index, scope.row)"
          >
            确定
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
  <!-- 分页 -->
  <div class="paging">
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      :page-size="size"
      @next-click="next"
      @prev-click="prev"
      @current-change="current"
    />
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import product from "../../../mock/index";
const router = useRouter();

const toDoodsAdd = () => {
  console.log("likaige");
  router.push("/home/add");
};

const value = ref("");
const options = [
  {
    value: "Option1",
    label: "Option1",
  },
];

// 异步页面数据请求
const tableData = ref([]);
const size = ref(12);
const page = ref(1);
const total = ref();
onMounted(async () => {
  const res = await product.getData({ page: page.value, size: size.value });
  if (res.status === 0) {
    tableData.value = [...res.result];
    total.value = res.count;
  }
});

// 分页
const current = async (val) => {
  page.value = val;
  const res = await product.getData({ page: page.value, size: size.value });
  if (res.status === 0) {
    tableData.value = [...res.result];
    total.value = res.count;
  }
};
const next = async (val) => {
  page.value = val;
  const res = await product.getData({ page: page.value, size: size.value });
  if (res.status === 0) {
    tableData.value = [...res.result];
    total.value = res.count;
  }
};
const prev = async (val) => {
  page.value = val;

  const res = await product.getData({ page: page.value, size: size.value });
  if (res.status === 0) {
    tableData.value = [...res.result];
    total.value = res.count;
  }
};
</script>

<style lang="less" scoped>
.all {
  .el-row {
    margin-bottom: 20px;
  }
  .el-row:last-child {
    margin-bottom: 0;
  }
  .el-col {
    border-radius: 4px;
  }

  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
  span {
    width: 71px;
    height: 18px;
    font-size: 16px;
    line-height: 36px;
    font-family: MicrosoftYaHei;
    font-weight: bold;
    color: #333333;
    margin-right: 11px;
  }
  :deep(.mingcheng) {
    .el-input__wrapper {
      max-width: 117px;
      height: 38px;
      border: 2px solid #cccccc;
    }
    .el-input__inner::placeholder {
      width: 36px;
      height: 18px;
      font-size: 14px;
      font-family: MicrosoftYaHei;
      font-weight: bold;
      color: #333333;
    }
  }
  :deep(.bianhao) {
    .el-input__wrapper {
      max-width: 187px;
      height: 38px;
      border: 2px solid #cccccc;
    }
    .el-input__inner::placeholder {
      width: 36px;
      height: 18px;
      font-size: 14px;
      font-family: MicrosoftYaHei;
      font-weight: bold;
      color: #333333;
    }
  }
  .add {
    width: 100%;
    height: 38px;
    background: #fcc284;
    font-weight: bold;
    color: #333333;
  }
  .remove {
    width: 100%;
    height: 38px;
    border: 2px solid #cccccc;
    font-weight: bold;
    color: #333333;
  }
  .reset {
    width: 100%;
    height: 38px;
    border: 2px solid #cccccc;
    font-weight: bold;
    color: #333333;
  }
  .sure {
    width: 100%;
    height: 38px;
    background: #fcc284;
    font-weight: bold;
    color: #333333;
  }
}
.form {
  margin-top: 16px;
  .cell {
    text-align: center;
  }
}
.paging {
  display: flex;
  justify-content: center;
  margin-top: 10px;
  // position: fixed;
  // left: 50%;
  // bottom: 10px;
  // transform: translateX(-50%);
}
</style>
